package com.gator.mybatis.parameter;


import java.sql.PreparedStatement;

/**
 * @Authror PABLO
 * @Date 2022/4/26 23:40
 * @Desc 参数的处理
 */
public class ParameterHandler {

    private PreparedStatement preparedStatement;

    public ParameterHandler(PreparedStatement preparedStatement) {
        this.preparedStatement = preparedStatement;
    }

    /**
     * @Description:
     * @Author: PABLO
     * @Date: 2022/4/26 23:46
     * @Params: [args]
     * @Return: void
     **/
    public void setParameter(Object[] args) {

        try {
            for (int i = 0; i < args.length; i++) {
                //序号从1开始
                int k = i + 1;
                if (args[i] instanceof Integer) {
                    preparedStatement.setInt(k, (Integer) args[i]);
                } else if (args[i] instanceof Long) {
                    preparedStatement.setLong(k, (Long) args[i]);
                } else if (args[i] instanceof String) {
                    preparedStatement.setString(k, String.valueOf(args[i]));
                } else if (args[i] instanceof Boolean) {
                    preparedStatement.setBoolean(k, (Boolean) args[i]);
                } else {
                    preparedStatement.setString(k, String.valueOf(args[i]));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
